// 引入本地存储
import { getUserInfo, setUserInfo } from '@/utils/storage'

export default {
  namespaced: true,
  state () {
    return {
      userInfo: getUserInfo() // 获取本地存储中的用户信息
    }
  },
  getters: {
  },
  mutations: {
    // 设置用户信息
    setUserInfo (state, obj) {
      state.userInfo = obj
      setUserInfo(obj)
    }
  },
  actions: {
    // 退出登录
    logout (context) {
      context.commit('setUserInfo', {})
      context.commit('cart/setCartList', [], { root: true })
    }
  }
}
